﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Core;
using Windows.Data.Xml.Dom;
using Windows.Security.Authentication.Identity.Provider;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;
using Windows.UI.Core;
using Windows.UI.Notifications;
using MyHelloWinJson;
using MyHelloWinDevice;
using Windows.Devices.Enumeration;
using Windows.Storage;

namespace Tasks
{
    public sealed class MyHelloWinTask : IBackgroundTask
    {
        static string m_TaskName_Unlock = "MyHelloWinTask_Unlock";
        HelloWinMonitor HelloWin = new HelloWinMonitor();
        static DeviceMonitor Device = new DeviceMonitor();
        
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // 标记任务延迟完成
            var deferral = taskInstance.GetDeferral();

            // 判断是不是枚举设备事件
            if (String.Equals(taskInstance.Task.Name, m_TaskName_Unlock))
            {
                HelloWin.DealWithUnlock();
            }
            else
            {
                DebugInfo.ShowToastNotification("收到设备通知");
                Device.DealWithDevice(taskInstance.Task.Name, taskInstance);
            }

            // 标记任务完成了
            deferral.Complete();
        }
    }
}